package week_5.LanmoyunExperiment;

public class ZipperMethod {
    LinearNode[] hashmap;//有节点的数组。
    int num = 11;//需要模的值
    int conflicttimes;//冲突次数

    int times;//平均查找的总次数。

    public ZipperMethod(int length)
    {
      hashmap = new LinearNode[length];
    }

    public void solveConfilt(int[] team)
    {//int[] team是由关键值构成的数组
      for (int i = 0; i < team.length; i++) {
            LinearNode newnode = new LinearNode(team[i]);
            int locate = team[i] % num;
            LinearNode node =hashmap[locate];

          if (node == null) {
                hashmap[locate] = newnode;
                times++;
            }
            else
                {
                    LinearNode current = hashmap[locate];
                    while (current.getNext() != null)
                    {
                        current = current.getNext();
                        times++;
                    }
                     current.setNext(newnode);
                     conflicttimes++;
                     times++;
                }
            }
        }
}
